<?php 
 include_once dirname(__FILE__)."/config.php";
 class mise_jour_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_id;
		 protected $_code_ue;
		 protected $_id_concepteur;
		 protected $_cin;
		 protected $_nature;
		 protected $_etat;
		 protected $_observation;
		 protected $_date_mj;
		 public function get_name_table(){ return "mise_jour";}
		 public function get_name_id(){ return "id";}
		 public function get_name_code_ue(){ return "code_ue";}
		 public function get_name_id_concepteur(){ return "id_concepteur";}
		 public function get_name_cin(){ return "cin";}
		 public function get_name_nature(){ return "nature";}
		 public function get_name_etat(){ return "etat";}
		 public function get_name_observation(){ return "observation";}
		 public function get_name_date_mj(){ return "date_mj";}
		 public function set_id($parametre){  $this->_id=$parametre;}	
		 public function set_code_ue($parametre){  $this->_code_ue=$parametre;}	
		 public function set_id_concepteur($parametre){  $this->_id_concepteur=$parametre;}	
		 public function set_cin($parametre){  $this->_cin=$parametre;}	
		 public function set_nature($parametre){  $this->_nature=$parametre;}	
		 public function set_etat($parametre){  $this->_etat=$parametre;}	
		 public function set_observation($parametre){  $this->_observation=$parametre;}	
		 public function set_date_mj($parametre){  $this->_date_mj=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_id(){ return $this->_id;}
		 public function get_code_ue(){ return $this->_code_ue;}
		 public function get_id_concepteur(){ return $this->_id_concepteur;}
		 public function get_cin(){ return $this->_cin;}
		 public function get_nature(){ return $this->_nature;}
		 public function get_etat(){ return $this->_etat;}
		 public function get_observation(){ return $this->_observation;}
		 public function get_date_mj(){ return $this->_date_mj;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 mise_jour(
			code_ue,
			id_concepteur,
			cin,
			nature,
			etat,
			observation,
			date_mj)
 VALUES(
			'".$this->_code_ue."',
			'".$this->_id_concepteur."',
			'".$this->_cin."',
			'".$this->_nature."',
			'".$this->_etat."',
			'".$this->_observation."',
			'".$this->_date_mj."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_code_ue)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
code_ue='".$this->_code_ue."'";
}
if(!empty($this->_id_concepteur)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
id_concepteur='".$this->_id_concepteur."'";
}
if(!empty($this->_cin)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
cin='".$this->_cin."'";
}
if(!empty($this->_nature)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
nature='".$this->_nature."'";
}
if(!empty($this->_etat)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
etat='".$this->_etat."'";
}
if(!empty($this->_observation)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
observation='".$this->_observation."'";
}
if(!empty($this->_date_mj)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
date_mj='".$this->_date_mj."'";
}
$sql="UPDATE 
mise_jour SET 
 ".$sql."
								WHERE id ='".$this->_id."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
mise_jour 
 
									WHERE id ='".$this->_id."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
mise_jour ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		id,
		code_ue,
		id_concepteur,
		cin,
		nature,
		etat,
		observation,
		date_mj
 FROM 
 mise_jour";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_id=$row->id;
		$this->_code_ue=$row->code_ue;
		$this->_id_concepteur=$row->id_concepteur;
		$this->_cin=$row->cin;
		$this->_nature=$row->nature;
		$this->_etat=$row->etat;
		$this->_observation=$row->observation;
		$this->_date_mj=$row->date_mj;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>